﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Sita.Entities;
using Sita.Data.Repositories;

namespace Sita.MainModule.Services
{
    public class VehicleService
    {
        VehicleRepository VehicleRepository;

        public VehicleService()
        {
            VehicleRepository = new VehicleRepository();
        }

        public IList<Vehicle> GetAllVehicles()
        {
            return VehicleRepository.GetAll().ToList();
        }

        public IList<Vehicle> GetPaginatedVehiclesByBussinesUnitID(int businessUnitID, int pageIndex, int pageSize, string sortColumn, bool ascending, int customerID, out int totalRows)
        {
            return VehicleRepository.GetPaginatedByBusinessUnitID(businessUnitID, pageIndex, pageSize, sortColumn, ascending, customerID, out totalRows);
        }

        public Vehicle GetVehicleByIDWithWO(int vehicleID)
        {
            return VehicleRepository.GetByIDWithWO(vehicleID);
        }

        public int AddVehicle(Vehicle vehicle)
        {
            VehicleRepository.Add(vehicle);

            VehicleRepository.StoreContext.Commit();

            return vehicle.VehicleID;
        }

        public Vehicle GetVehicleByID(int vehicleID)
        {
            return VehicleRepository.GetByID(vehicleID);
        }

        public bool ModifyVehicle(Vehicle vehicle)
        {
            VehicleRepository.Modify(vehicle);

            VehicleRepository.StoreContext.Commit();

            return true;
        }

        public bool DeleteVehicle(Vehicle vehicle)
        {
            VehicleRepository.Delete(vehicle);

            VehicleRepository.StoreContext.Commit();

            return true;
        }
    }
}
